<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <!-- load css -->
    <link rel="stylesheet" th:href="@{/css/font.css}" />
	<link rel="stylesheet" th:href="@{/css/xadmin.css}" />
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body class="layui-anim layui-anim-fadein">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a>交易管理</a>
        <a><cite>交易记录</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input id="id" type="text" name="id"   placeholder="平台订单号" autocomplete="off" class="layui-input">
          <input id="merchant_order_no" type="text" name="merchant_order_no"  placeholder="商户订单号" autocomplete="off" class="layui-input">
          <input id="official_order_no" type="text" name="official_order_no"  placeholder="官方单号" autocomplete="off" class="layui-input">
          <input id="amount" type="text" name="amount"  placeholder="订单金额" autocomplete="off" class="layui-input">
          <input id="account" type="text" name="account"   placeholder="下单账号" autocomplete="off" class="layui-input">
          <input id="charge_account" type="text" name="charge_account"   placeholder="充值账号" autocomplete="off" class="layui-input">
          <!-- <div class="layui-input-inline">
            <select id="merchant_id" name="merchant_id">
              <option value="">商户</option>
              <option th:each="m : ${merchants}" th:value="${m.id}" th:text="${m.name}"></option>
            </select>
          </div> -->
         <!--  <div class="layui-input-inline">
            <select id="goods_type" name="goods_type">
              <option value="">商品类型</option>
              <option value="1">缴纳电费</option>
            </select>
          </div> -->
          <div class="layui-input-inline">
            <select id="pay_type" name="pay_type">
               <option value="">支付类型</option>
               <option value="alipay">支付宝</option>
               <option value="alipaySdk">支付宝sdk</option>
               <option value="wechat">微信</option>
               <option value="wechatScan">微信扫码</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="status" name="status">
              <option value="">订单状态</option>
              <option value="0">未支付</option>
              <option value="5">支付确认中</option>
              <option value="1">已支付</option>
              <option value="3">延迟到账</option>
              <option value="4">产码失败</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="notify_status" name="notify_status">
              <option value="">回调状态</option>
              <option value="0">未回调</option>
              <option value="1">已回调</option>
            </select>
          </div>
          <button id="searchBtn" data-type="reload" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </div>
      </div>
       <xblock>
         <span style="color: green;margin-left: 10px;">剩余库存：<span th:text="${leftAmount}"></span> (元)</span>
       </span>
            <!-- <button id="allNotify"  style="margin-left: 30px;font-weight: bold;float: right;margin-right: 20px;">一键回调</button> -->
    </xblock>
      <table class="layui-hide" id="table1" lay-filter="tool1"></table>
      <script type="text/html" id="bar1">
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">查单</a>
 		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="callback">补单</a>
		</script>
      </div>
<script type="text/html" id="statusTpl">
{{#   if(d.status == 0){ }}
<span>未支付</span>
{{#  }else if(d.status == -1){  }}
<span style="color: blue;">产码中</span>
{{#  }else if(d.status == 5){  }}
<span style="color: blue;">支付确认中</span>
{{#  }else if(d.status == 1){  }}
<span style="color: green;">已支付</span>
{{#  }else if(d.status == 3){  }}
<span style="color:#FF00FF;">延迟到账</span>
{{#  }else if(d.status == 4){  }}
<span style="color: red;">产码失败</span>
{{#  }  }}
</script>
<script type="text/html" id="notifyStatusTpl">
{{#  if(d.notify_status == 0){ }}
<span>未回调</span>
{{#  }else if(d.notify_status == 1){  }}
<span style="color: green;">已回调</span>
{{#  }  }}
</script>
<script type="text/html" id="payTypeTpl">
{{#  if(d.pay_type == 'wechat'){  }}
<span style="color: green;">微信</span>
{{#  }else if(d.pay_type == 'wechatScan'){  }}
<span style="color: green;">微信扫码</span>
{{#  }else if(d.pay_type == 'alipay'){  }}
<span style="color: blue;">支付宝</span>
{{#  }else if(d.pay_type == 'alipaySdk'){  }}
<span style="color: blue;">支付宝sdk</span>
{{#  }  }}
</script>
<script type="text/html" id="goodsTypeTpl">
{{#  if(d.goods_type == 1){ }}
<span style="color: green;">缴纳电费</span>
{{#  }  }}
</script>
<script type="text/html" id="tipTpl">
{{#  if(d.status == 4){ 
return '<span style="color: red;">'+d.remarks+'</span>';
 }
else 
return d.official_order_no;
 }}
</script>
<script>
      layui.use(['laydate', 'laypage', 'table'], function(){
        var laydate = layui.laydate,
        table = layui.table, //表格
        laypage = layui.laypage; //分页
        //执行一个 table 实例
        table.render({
          elem: '#table1'
          ,height: 680
          ,limit: 15
          ,limits:[15,20,30,40,50,100]
          ,url: '[[@{/admin/order/list.html}]]' //数据接口
          ,id:'table1'
          ,page: true
          ,cols: [
           [
        	   {field: 'id', title: '平台订单号', width:'7%', sort: true, align:'center',fixed: 'left'}
               ,{field: 'merchant_order_no', title: '商户订单号', width:'8%', align:'center'}
               ,{field: 'merchant_id', title: '商户号', width:'6%', align:'center'}
               ,{field: 'official_order_no', title: '官方单号', width:'8%', align:'center',templet:'#tipTpl'}
               ,{field: 'amount', title: '订单金额', align:'center', width:'6%'}
               ,{field: 'pay_type', title: '支付类型', width:'7%', align:'center',templet:'#payTypeTpl'}
               ,{field: 'account', title: '下单账号', width:'8%', align:'center'}
               ,{field: 'charge_account', title: '充值账号', width:'8%', align:'center'}
               /* ,{field: 'goods_type', title: '商品类型', width:'8%', align:'center',templet:'#goodsTypeTpl'} */
               ,{field: 'device_type', title: '设备类型', width:'6%', align:'center'}
               ,{field: 'create_time', title: '下单时间', align:'center', width: '11%'}
               ,{field: 'status', title: '状态', width: '7%',templet:'#statusTpl', align:'center'}
               ,{field: 'notify_status', title: '回调状态', width: '7%',templet:'#notifyStatusTpl', align:'center'}
               ,{fixed: 'right', title: '操作',align:'center', toolbar: '#bar1', width:'10%'}
          ]
          ]
        });
        $('#searchBtn').on('click', function(){
        	var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        	table.reload('table1', {
    	        page: {
    	          curr: 1 //重新从第 1 页开始
    	        }
    	        ,where: {
    	        	'id': $('#id').val(),
    	            'merchant_order_no':$('#merchant_order_no').val(),
    	            'official_order_no':$('#official_order_no').val(),
    	            'merchant_id': $('#merchant_id').val(),
    	            'pay_type': $('#pay_type').val(),
    	            'account': $('#account').val(),
    	            'charge_account': $('#charge_account').val(),
    	            'status': $('#status').val(),
    	            'goods_type': $('#goods_type').val(),
    	            'amount': $('#amount').val(),
    	            'notify_status': $('#notify_status').val(),
    	        }
    	      });
        	layer.close(index);
       });
        
        $('#allNotify').on('click', function(){
        	layer.confirm('确认操作？', function(index){
                $.post('[[@{/admin/order/allNotify.html}]]',{},function(data){
              	  layer.close(index);
              	  if(data.code==0)
              	  {
              	  	 layer.msg(data.msg);
              		  table.reload('table1', {
                	        page: {
                	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                	        }
                	        ,where: {
                	        	'id': $('#id').val(),
                	            'merchant_order_no':$('#merchant_order_no').val(),
                	            'official_order_no':$('#official_order_no').val(),
                	            'merchant_id': $('#merchant_id').val(),
                	            'pay_type': $('#pay_type').val(),
                	            'account': $('#account').val(),
                	            'charge_account': $('#charge_account').val(),
                	            'status': $('#status').val(),
                	            'goods_type': $('#goods_type').val(),
                	            'amount': $('#amount').val(),
                	            'notify_status': $('#notify_status').val(),
                	        }
                	      });
              	  }
              	  else
              	  {
              		  layer.msg('操作失败');
              	  }
                })
              });
       });
        
      //监听工具条
        table.on('tool(tool1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data //获得当前行数据
          ,layEvent = obj.event; //获得 lay-event 对应的值
          if(layEvent === 'detail'){
        	  	x_admin_show('查单','[[@{/admin/order/detailPage.html?accountId=}]]'+data.account_id+'&orderId='+data.id,300,200);
          } else if(layEvent === 'callback'){
        	  layer.prompt({title: '请输入超级密码', formType: 1}, function(safeCode, index){
        		  $.post('[[@{/admin/order/notify.html}]]',{'orderId':data.id,'password':safeCode},function(data)
               	          {
           			  		layer.msg(data.msg);
               	      		if(data.code==0)
               	      		{
               	      			//layer.alert(data.msg, {icon: 6},function () {
               	      				table.reload('table1', {
                                 	        page: {
                                 	        	curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                                 	        }
                                 	        ,where: {
                                 	        	'id': $('#id').val(),
                                	            'merchant_order_no':$('#merchant_order_no').val(),
                                	            'official_order_no':$('#official_order_no').val(),
                                	            'merchant_id': $('#merchant_id').val(),
                                	            'pay_type': $('#pay_type').val(),
                                	            'account': $('#account').val(),
                                	            'charge_account': $('#charge_account').val(),
                                	            'status': $('#status').val(),
                                	            'goods_type': $('#goods_type').val(),
                                	            'amount': $('#amount').val(),
                                	            'notify_status': $('#notify_status').val(),
                                 	        }
                                 	      });
            	                  // });
               	      		}
               	          });
        		});
          } else if(layEvent === 'del'){
          }
        });
      });
    </script>
  </body>
</html>
